from xml.dom.minidom import parse
import xml.dom.minidom
import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))
song_infofile = open("SongInfo.txt","w")
DOMTree = xml.dom.minidom.parse("songs.xml") #Opening the XML document
genre=DOMTree.documentElement
if genre.hasAttribute('catalogue'):
    print('Root:'+ genre.getAttribute("catalogue"))
    song_infofile.write('Root:'+ genre.getAttribute("catalogue"))
    song_infofile.write('\n')
songs=genre.getElementsByTagName('song') #Get all songs in the genre Pop

for song in songs:
    print('Song:')
    song_infofile.write('Song:')
    song_infofile.write('\n')
    if song.hasAttribute('title'):
        print('Title:'+song.getAttribute("title"))
        song_infofile.write('Title:'+song.getAttribute("title"))
        song_infofile.write('\n')
    artist=song.getElementsByTagName('artist')[0]
    print('Artist:'+artist.firstChild.data)
    song_infofile.write('Artist:'+artist.firstChild.data)
    song_infofile.write('\n')
    year=song.getElementsByTagName('year')[0]
    print('Release Year:'+ year.firstChild.data)
    song_infofile.write('Release Year:'+ year.firstChild.data)
    song_infofile.write('\n')
    album=song.getElementsByTagName('album')[0]
    print('Album:'+album.firstChild.data)
    song_infofile.write('Album:'+album.firstChild.data)
    song_infofile.write('\n')
song_infofile.close()